package com.acoreful.acf2admin.commons.base;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public abstract class AbstractResourcePreloaderListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext sc = sce.getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		preload(wac);
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// do nothing.
	}
	
	protected abstract void preload(ApplicationContext applicationContext);

}